package com.an.nopro.app;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName: WebConfiguration
 * @Description: TODO(自定义过滤器，并将过滤器添加到过滤器链中)
 * @author antch,861710865@qq.com
 * @date 2017年8月6日 下午10:15:51
 * 
 */
@Configuration
public class WebConfiguration {

//	public TemplateReso
	
//	public SpringResourceTemplateResolver
	/*ThymeleafProperties ddd;
	@Bean
	public RemoteIpFilter remoteIpFilter() {
		return new RemoteIpFilter();
	}*/
	
	@Bean
	public FilterRegistrationBean testFilter() {
		FilterRegistrationBean registrationBean = new FilterRegistrationBean();
		registrationBean.setFilter(new MyFilter());
		registrationBean.addUrlPatterns("/*");
		registrationBean.addInitParameter("anzi", "啊每天吃");
		registrationBean.setName("MyFilter_haha");
		registrationBean.setOrder(1);
		return registrationBean;
	}

	public class MyFilter implements Filter {

		@Override
		public void destroy() {
			// TODO Auto-generated method stub
			System.out.println("自定义过滤器销毁。");

		}

		@Override
		public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
				throws IOException, ServletException {
			HttpServletRequest request = (HttpServletRequest) arg0;
			System.out.println("this is MyFilter,url :" + request.getRequestURI());
			arg2.doFilter(arg0, arg1);

		}

		@Override
		public void init(FilterConfig arg0) throws ServletException {
			// TODO Auto-generated method stub
			System.out.println("自定义过滤器初始化。");
		}

	}
}
